library(vegan)

# Script for filtering are rarefying nasal 16S OTU table, generates table to use across notebooks

abunds = read.table('../../data/nasal/otu_table.tsv', header=T, row.names=2)
drops <- c("label", "numOtus")
abunds = abunds[ , !(names(abunds) %in% drops)]

abunds_gt10 = abunds[colSums(abunds) >= 10]
abunds_gt10_min10K = abunds_gt10[rowSums(abunds_gt10) >= 10000,]

abunds_gt10_rar10K = rrarefy(abunds_gt10_min10K, 10000)
abunds_gt10_rar10K = abunds_gt10_rar10K[,colSums(abunds_gt10_rar10K) > 0]

write.table(abunds_gt10_rar10K, '../../data/nasal/otu_table.gt10_rar10K.tsv', sep='\t', quote=F)
